package com.deelete.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.deelete.springcloud.pojo.Order;
import com.deelete.springcloud.service.OrderService;
import com.deelete.springcloud.service.fallback.OrderFallback;
import com.deelete.springcloud.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping("/testA")
    public String testA(){
        return System.currentTimeMillis()+"";
    }


    @RequestMapping("/order/add")
    public Boolean addOrder(Order order){
        if (order==null){
            return false;
        }else{
            return orderService.addOrder(order);
        }
    }

    /**
     * 下订单
     * @param order 订单信息
     * @return
     */
    @GetMapping("/order/create")
    @SentinelResource(value = "createOrder",
            fallback = "orderCreateFallback",
            fallbackClass = com.deelete.springcloud.service.fallback.OrderFallback.class
    )
    public CommonResult<Order> createOrder(Order order){
        if(order==null){
            return new CommonResult<Order>(CommonResult.STATUS_ERROR,"订单不能为空");
        }else{
            return orderService.createOrder(order);
        }
    }


}
